package mx.com.switz.peliculas.dao.impl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;


import org.springframework.stereotype.Repository;


import mx.com.switz.peliculas.dao.PrestamoDao;
import mx.com.switz.peliculas.dto.Socio;
import mx.com.switz.peliculas.vo.PeliculasSocio;
@Repository
public class PrestamoDaoImpl extends JdbcDaoSupport implements PrestamoDao{

	private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
	@Autowired
	public PrestamoDaoImpl(DataSource dataSource){
		setDataSource(dataSource);
		this.namedParameterJdbcTemplate= new NamedParameterJdbcTemplate(dataSource);
	}
	
	@Override
	public List<PeliculasSocio> selectPrestamoBySocio(Socio socio) {
		// TODO Auto-generated method stub
		System.out.println("estamos en Dao con id: "+socio.getId());
		String query="SELECT  pelicula.ID,pelicula.titulo,pelicula.clasificacion,pelicula.genero,prestamo.fechaSalida,prestamo.fechaEntrega "
				+ "FROM socio INNER JOIN prestamo,pelicula "
		+ "WHERE  prestamo.idSocio = :id  AND prestamo.idPelicula=pelicula.ID";
		//String query = "SELECT * from socio where  nombre= :nombre";
		SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(socio);
		List socios=namedParameterJdbcTemplate.query(query,
		namedParameters, ParameterizedBeanPropertyRowMapper.newInstance(PeliculasSocio.class));
		return socios;

	}

}
